﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once

#include "GmFamilyCustomData.h"
#include "ICurve2d.h"
#include "IParameterCustomData.h"
#include "NdbDataSchema.h"
#include "NdbObjectSchematic.h"

#define ROOF_CUSTOM_DATA_ID   L"RoofCustomDataId"

namespace gcmp
{
    // 坡度线信息
    class GM_FAMILY_CUSTOM_DATA_EXPORT SlopeLineData : public NdbObjectSchematic
    {
        CANNOT_COPY_OR_ASSIGN(SlopeLineData)
        DATA_BEGIN(gcmp, SlopeLineData, gcmp::NdbObjectSchematic, E97ED6FB - 6FA1 - 45E5 - A43D - 21071039CC09, gmfamilycustomdata)
            DATA(OwnerPtr<ICurve2d>, SlopeLine)
            DATA(double, SlopeAngle)
            DATA_TRANSIENT(IElement*, pOwnerElement)

        DATA_END

    public:
        SlopeLineData(const ICurve2d* slopeLine, double slopeAngle);
        virtual ~SlopeLineData();

    public:
        double GetSlopeAngle() const;
        const ICurve2d* GetSlopeLine() const;

        void SetSlopeLine(OwnerPtr<ICurve2d> opCurve2d);
        void SetSlopeAngle(double value);

        OwnerPtr<SlopeLineData> Clone() const;

        bool IsLessThan(const SlopeLineData* pOther) const;
        bool HasSameValue(const SlopeLineData* pOther) const;
    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override;


        bool SetOwnerElement(IElement* pOwnerElement) { m_pOwnerElement = pOwnerElement; return true; }

    };


    // 轮廓线信息
    class GM_FAMILY_CUSTOM_DATA_EXPORT ProfileCurveData : public NdbObjectSchematic
    {
        CANNOT_COPY_OR_ASSIGN(ProfileCurveData)
        DATA_BEGIN(gcmp, ProfileCurveData, gcmp::NdbObjectSchematic, 9F7C3712 - D3D7 - 4A5D - 8CC1 - E3AE2720F6EF, gmfamilycustomdata)
            DATA(OwnerPtr<ICurve2d>, ProfileCurve)
            DATA(Bool, IsDefineSlope)                       // 轮廓线是否定义坡度
            DATA(double, SlopeAngle)                        // 轮廓线定义的坡度角
            DATA(double, ProfileCurveOffset)                // 轮廓线与屋顶基准的偏移
            DATA(OwnerPtr<SlopeLineData>, SlopeLineData)    // 轮廓线对应的坡度线信息
            DATA_TRANSIENT(IElement*, pOwnerElement)

        DATA_END

    public:
        ProfileCurveData(const ICurve2d* pProfileCurve, bool isDefineSlope, double slopeAngle, double profileCurveOffset, const SlopeLineData* pSlopeLineData);
        virtual ~ProfileCurveData();

    public:
        const ICurve2d*  GetProfileCurve() const;
        bool GetIsDefineSlope() const;
        double GetSlopeAngle() const;
        double GetProfileCurveOffset() const;        
        const SlopeLineData* GetSlopeLineData() const;

        void SetProfileCurve(OwnerPtr<ICurve2d> opCurve2d);
        void SetIsDefineSlope(bool value);
        void SetSlopeAngle(double value);
        void SetProfileCurveOffset(double value);
        void SetSlopeLineData(OwnerPtr<SlopeLineData> opSlopeLineData);
        bool IsLessThan(const ProfileCurveData* pOther) const;
        bool HasSameValue(const ProfileCurveData* pOther) const;
        OwnerPtr<ProfileCurveData> Clone() const;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override;


        bool SetOwnerElement(IElement* pOwnerElement) { 
            m_pOwnerElement = pOwnerElement; 
            if(m_SlopeLineData)
                m_SlopeLineData->SetOwnerElement(pOwnerElement);
            return true; 
        }

    };


    // 屋顶自定义数据
    class GM_FAMILY_CUSTOM_DATA_EXPORT RoofCustomData : public IParameterCustomData
    {
        CANNOT_COPY_OR_ASSIGN(RoofCustomData)
        DATA_BEGIN(gcmp, RoofCustomData, gcmp::NdbObjectSchematic, 6009E1F2 - 5662 - 4404 - A4EC - 731A72288962, gmfamilycustomdata)
            ARR_DATA(OwnerPtr<ProfileCurveData>, ProfileCurveData)
            DATA_TRANSIENT(IElement*, pOwnerElement)

        DATA_END

    public:
        virtual ~RoofCustomData();

        std::vector<OwnerPtr<ProfileCurveData>>& GetProfileCurveData();
        const std::vector<OwnerPtr<ProfileCurveData>>& GetProfileCurveData() const;
        bool SetProfileCurveData(std::vector<OwnerPtr<ProfileCurveData>>&& profileCurves);
        bool AddProfileCurveData(OwnerPtr<ProfileCurveData> opProfileCurveData);

        virtual bool IsLessThan(const IParameterCustomData* pOther) const override;
        virtual bool HasSameValue(const IParameterCustomData* pOther) const override;
        virtual std::wstring GetCustomDataId() const override;
        virtual Int32 GetVersion() const override;
        virtual OwnerPtr<IParameterCustomData> Clone() const override;
        virtual void GetReferencedElementIds(std::vector<ElementId>& referenceElementIds) const override;

    public: //实现NdbObject接口
        virtual NdbObject* GetTopOwnerObject() const override;


        bool SetOwnerElement(IElement* pOwnerElement) 
        {
            m_pOwnerElement = pOwnerElement; 
            for (size_t i = 0; i < m_ProfileCurveData.size(); i++)
            {
                if(m_ProfileCurveData[i])
                    m_ProfileCurveData[i]->SetOwnerElement(pOwnerElement);
            }
            return true; 
        }

    };
}
